﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace VirtualDisk
{
    class FileNode:DiskNode
    {
        //文件节点的数据
        private Byte[] data = null;

        public FileNode(MyString name, DateTime date)
            : base(name, date)
        {
            data = new Byte[0];
        }

        //文件大小
        public int Size
        {
            get
            {
                return data.Length;
            }
        }

        //文件数据
        public Byte[] FileData
        {
            get
            {
                return (Byte[])data.Clone();
            }
        }

        //流写入文件数据
        public void setData(Stream stm)
        {
            data = new Byte[stm.Length];
            using (BinaryReader rd = new BinaryReader(stm))
            {
                rd.Read(data, 0, data.Length);
            }

        }


        public override void showInfo(ShowOptions option)
        {
            int numOfFile = 1;
            int numOfDirc = 0;
            int size = Size;
            Console.WriteLine(this.ToString());
            Console.WriteLine("        文件 " + numOfFile + " 个        " +size+"字节");
            Console.WriteLine("        目录 " + numOfDirc + " 个");
            Console.WriteLine();
            Console.WriteLine();
        }

        public override void showAllInfo(ShowOptions option)
        {
            showInfo(option);
        }

        public override void addNode(DiskNode n)
        {
            throw new FileCantAddChildException();
        }

        public override void removeNode(DiskNode n)
        {
            throw new FileCantRemoveChildException();
        }


        public override string ToString()
        {
            String type = "     ";
            String size = this.Size.ToString();
            return this.CreateDate.ToString() + "   " + type + "  " + size + "    " + this.Name.ToString();
        }

    }
}
